package com.cloudkinto.controller.home;

import com.cloudkinto.base.BaseController;

import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.dto.home.HomeOrderDto;
import com.cloudkinto.dto.home.HomeTodoData;
import com.cloudkinto.dto.home.StockInWhRes;
import com.cloudkinto.service.home.HomePageService;
import com.cloudkinto.service.home.vo.HomeCostRes;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@Api(tags = "WMS首页统计模块")
@RequestMapping("api/admin/wms/HomePage")
public class HomePageWmsController extends BaseController {
    @Autowired
    private HomePageService service;


    @UserSessionRequired
    @GetMapping("/getTodoData")
    @ApiOperation(value = "首页最上方统计", notes = "首页最上方统计")
    @ApiResponses({@ApiResponse(code = 200, message = "", response = HomeTodoData.class)})
    public SingleResult getTodoData() {
        List<HomeTodoData> toDealMsg = service.getTodoData("wms", getCurrentUserId(), null, getWarehouseId(), getTenantId());
        return SingleResult.success(toDealMsg);
    }


    @UserSessionRequired
    @GetMapping("/getOrderFinishCount")
    @ApiOperation(value = "单量分析/累计单量(要排序)", notes = "单量分析/累计单量(要排序)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "beginTime", value = "开始时间"),
            @ApiImplicitParam(name = "endTime", value = "结束时间"),
            @ApiImplicitParam(name = "sort", value = "排序规则 累计单量才需要"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "", response = HomeTodoData.class)})
    public SingleResult getOrderFinishCount(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        String beginTime = request.getParameter("beginTime");
        String endTime = request.getParameter("endTime");
        String sort = request.getParameter("sort");
        map.put("sort", sort);
        map.put("beginTime", beginTime);
        map.put("endTime", endTime);
        map.put("source", "wms");
        map.put("companyId", null);
        map.put("whId", getWarehouseId());
        map.put("userId", getCurrentUserId());
        map.put("tenantId", getTenantId());
        List<HomeTodoData> toDealMsg = service.getOrderFinishCount(map);
        return SingleResult.success(toDealMsg);
    }


    @UserSessionRequired
    @GetMapping("/getHomeOrderDto")
    @ApiOperation(value = "单量分析(按天)oms", notes = "单量分析(按天)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "beginTime", value = "开始时间"),
            @ApiImplicitParam(name = "endTime", value = "结束时间"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "", response = HomeOrderDto.class)})
    public SingleResult getHomeOrderDto(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        String beginTime = request.getParameter("beginTime");
        String endTime = request.getParameter("endTime");
        String sort = request.getParameter("sort");
        map.put("sort", sort);
        map.put("beginTime", beginTime);
        map.put("endTime", endTime);
        map.put("source", "wms");
        map.put("whId", getWarehouseId());
        map.put("userId", getCurrentUserId());
        map.put("tenantId", getTenantId());
        List<HomeOrderDto> toDealMsg = service.getHomeOrderDto(map);
        return SingleResult.success(toDealMsg);
    }

    @UserSessionRequired
    @GetMapping("/getStockInWh")
    @ApiOperation(value = "库存", notes = "库存")
    @ApiResponses({@ApiResponse(code = 200, message = "", response = StockInWhRes.class)})
    public SingleResult getStockInWh() {
        StockInWhRes wms = service.getStockInWh("wms", getCurrentUserId(), null, getWarehouseId(), getTenantId());
        return SingleResult.success(wms);
    }


    @UserSessionRequired
    @GetMapping("/getHomeCostDto")
    @ApiOperation(value = "费用", notes = "费用")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "beginTime", value = "开始时间"),
            @ApiImplicitParam(name = "endTime", value = "结束时间"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "", response = HomeCostRes.class)})
    public SingleResult getHomeCostDto(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        String beginTime = request.getParameter("beginTime");
        String endTime = request.getParameter("endTime");
        String sort = request.getParameter("sort");
        map.put("sort", sort);
        map.put("beginTime", beginTime);
        map.put("endTime", endTime);
        map.put("source", "wms");
        map.put("userId", getCurrentUserId());
        map.put("whId", getWarehouseId());
        map.put("tenantId", getTenantId());
        HomeCostRes homeCostDto = service.getHomeCostDto(map);
        return SingleResult.success(homeCostDto);
    }
}
